export function useDebounce<T extends (...args: any[]) => any, U extends any[]>(fn: T, delay = 300) {
  let timeoutId: any = null

  return function (this: any, ...args: U) {
    clearTimeout(timeoutId as number)
    timeoutId = setTimeout(() => {
      fn.apply(this, args)
    }, delay)
  } as (...args: U) => void
}
